package cn.rengy.web.framework.web;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.rengy.lang.ResultEntity;
import cn.rengy.web.framework.sql.DbService;


/**
 * ajax请求
 * 
 */
@RestController
@RequestMapping(value = "/open")
public class RiskAjaxController {
	private static Logger logger = LoggerFactory.getLogger(RiskAjaxController.class);
	
	@Autowired
	private DbService dbService;
	
	@RequestMapping(value="/update/{id}",method = RequestMethod.POST)
	public ResultEntity<?> update (@PathVariable("id") String sqlid,@RequestBody Map<String,Object> paramMap){
		sqlid="open-"+sqlid;
		return ResultEntity.ok(dbService.updateMapParameter(sqlid, paramMap));
	}
	@RequestMapping(value="/map/{id}",method = RequestMethod.POST)
	public ResultEntity<?> map(@PathVariable("id") String sqlid,@RequestBody(required=false) Map<String,Object> paramMap){
		sqlid="open-"+sqlid;
		return ResultEntity.ok(dbService.queryForMapParameter(sqlid, paramMap==null?new HashMap<String,Object>():paramMap));
	}
	@RequestMapping(value="/{id}",method = RequestMethod.POST)
	public ResultEntity<?> query (@PathVariable("id") String sqlid,@RequestBody(required=false) Map<String,Object> paramMap){
		sqlid="open-"+sqlid;
		return ResultEntity.ok(dbService.queryForListMapParameter(sqlid, paramMap==null?new HashMap<String,Object>():paramMap));
	}
}
